﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Game.Facade;
using Game.Kernel;
using Game.Utils;
using Game.Entity.Accounts;

namespace Game.Card
{
    public partial class UpdatePass : AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SiteMaster.Menu = 0;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            //获取数据
            string password = CtrlHelper.GetText(txtLoginPass);
            string newpassword = CtrlHelper.GetText(txtNewPass);
            string repassword = CtrlHelper.GetText(txtRePass);

            //数据验证
            if(string.IsNullOrEmpty(password))
            {
                ShowInfo("抱歉，原密码不能为空");
                return;
            }
            if(string.IsNullOrEmpty(newpassword))
            {
                ShowInfo("抱歉，新密码不能为空");
                return;
            }
            if(newpassword!= repassword)
            {
                ShowInfo("抱歉，两次密码输入不一致");
                return;
            }

            //执行修改操作
            Message umsg = FacadeManage.aideAccountsFacade.ModifyLogonPasswd(userTicket.UserID, TextEncrypt.EncryptPassword(password), TextEncrypt.EncryptPassword(newpassword), GameRequest.GetUserIP());
            if(umsg.Success)
            {
                Fetch.DeleteUserCookie();
                Response.Redirect("/Login.aspx");
            }
            else
            {
                ShowInfo("抱歉，修改失败，请稍后重试");
            }
        }
    }
}